/**
 *  Copyright 2002-2009 the original author or authors.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package foo.bar.blog.web.action;

import java.util.EnumSet;
import java.util.Set;

/**
 * Represents the month in a year.
 *
 * @author tmjee
 * @version $Date: 2009-03-14 06:53:07 +0000 (Sat, 14 Mar 2009) $ $Id$
 */
public enum MonthEnum {
    
    JANUARY(){  public int month(){return java.util.Calendar.JANUARY;}
                public MonthEnum next() { return FEBRUARY; }
                public MonthEnum previous() { return null; }},
    FEBRUARY(){ public int month(){return java.util.Calendar.FEBRUARY;}
                public MonthEnum next() { return MARCH; }
                public MonthEnum previous() { return MonthEnum.JANUARY; }},
    MARCH(){    public int month(){return java.util.Calendar.MARCH;}
                public MonthEnum next() { return APRIL; }
                public MonthEnum previous() { return MonthEnum.FEBRUARY; }},
    APRIL(){    public int month(){return java.util.Calendar.APRIL;}
                public MonthEnum next() { return MAY; }
                public MonthEnum previous() { return MonthEnum.MARCH; }},
    MAY(){      public int month(){return java.util.Calendar.MAY;}
                public MonthEnum next() { return JUNE; }
                public MonthEnum previous() { return MonthEnum.APRIL; }},
    JUNE(){     public int month(){return java.util.Calendar.JUNE;}
                public MonthEnum next() { return JULY; }
                public MonthEnum previous() { return MonthEnum.MAY; }},
    JULY(){     public int month(){return java.util.Calendar.JULY;}
                public MonthEnum next() { return AUGUST; }
                public MonthEnum previous() { return MonthEnum.JUNE; }},
    AUGUST(){   public int month(){return java.util.Calendar.AUGUST;}
                public MonthEnum next() { return SEPTEMBER; }
                public MonthEnum previous() { return MonthEnum.JULY; }},
    SEPTEMBER(){public int month(){return java.util.Calendar.SEPTEMBER;}
                public MonthEnum next() { return OCTOBER; }
                public MonthEnum previous() { return MonthEnum.AUGUST; }},
    OCTOBER(){  public int month() {return java.util.Calendar.OCTOBER;}
                public MonthEnum next() { return NOVEMBER; }
                public MonthEnum previous() { return MonthEnum.SEPTEMBER;}},
    NOVEMBER(){ public int month(){return java.util.Calendar.NOVEMBER;}
                public MonthEnum next() { return DECEMBER; }
                public MonthEnum previous() { return MonthEnum.OCTOBER; }},
    DECEMBER(){ public int month(){return java.util.Calendar.DECEMBER;}
                public MonthEnum next() { return null; }
                public MonthEnum previous() { return MonthEnum.NOVEMBER; }};

    public abstract int month();
    public abstract MonthEnum next();
    public abstract MonthEnum previous();

    public static MonthEnum convert(String _month) {
        Set<MonthEnum> months = EnumSet.allOf(MonthEnum.class);
        for (MonthEnum month: months) {
            if (month.name().equalsIgnoreCase(_month)) {
                return month;
            }
        }
        return null;
    }

    public static MonthEnum convert(int _month) {
        Set<MonthEnum> months = EnumSet.allOf(MonthEnum.class);
        for (MonthEnum month: months) {
            if (month.month() == _month) {
                return month;
            }
        }
        return null;
    }
}
